package logic

import (
	"context"
	"doc-manage/model/models"
	"doc-manage/model/mysql"

	"doc-manage/docrpc/docrpc"
	"doc-manage/docrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DocDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDocDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocDetailLogic {
	return &DocDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DocDetailLogic) DocDetail(in *docrpc.DocDetailRequest) (*docrpc.DocDetailResponse, error) {
	// todo: add your logic here and delete this line

	var doc models.Doc
	err := doc.DocDetail(mysql.DB, in.DocId)
	if err != nil {
		return nil, err
	}

	return &docrpc.DocDetailResponse{
		DocId:      int64(doc.ID),
		DocName:    doc.DocName,
		DocType:    doc.DocType,
		DocContent: doc.DocContent,
	}, nil
}
